/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.common.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


import com.koron.common.bean.KpiStatisticsBean;
import com.koron.common.domain.KpiStatistics;

public interface KpiStatisticsMapper {
	
	@Insert("insert into kpi_statistical(kpi_id,kpi_name,kpi_code,kpi_value,date_type,date_value,statistical_type,object_id,object_name,add_time)"
			+ "values(#{kpiId},#{kpiName},#{kpiCode},#{kpiValue},#{dateType},#{dateValue},#{statisticalType},#{objectId},#{objectName},#{addTime})")
	int insert(KpiStatistics bean);
	
	@Insert("<script>"
			+ "insert into kpi_statistical(kpi_id,kpi_name,kpi_code,kpi_value,date_type,date_value,statistical_type,object_id,object_name,add_time) values"
			+ "<foreach collection ='beanList' item='item' index='index' separator =','>"
			+ "(#{item.kpiId},#{item.kpiName},#{item.kpiCode},#{item.kpiValue},#{item.dateType},#{item.dateValue},#{item.statisticalType},#{item.objectId},#{item.objectName},#{item.addTime}) </foreach>"
			+ "</script>")
	int batchInsert(@Param("beanList") List<KpiStatistics> beanList);
	
	@Delete("<script>"
			+ "delete from kpi_statistical where kpi_code=#{kpiCode}"
			+ "<if test='dateValue!=null'> and date_value=#{dateValue} </if>"
			+ "<if test='objectId!=null'> and object_id=#{objectId} </if>"
			+ "</script>")
	int delete(@Param("kpiCode") String kpiCode,@Param("dateValue") String dateValue,@Param("objectId") String objectId);
	
	@Select("<script>"
			+ "select * from kpi_statistical where 1=1"
			+ "<if test='kpiId!=null and !kpiId.isEmpty()'> and kpi_id=#{kpiId} </if>"
			+ "<if test='kpiName!=null'> and kpi_name like CONCAT(CONCAT('%',#{kpiName}),'%') </if>"
			+ "<if test='kpiCode!=null and !kpiCode.isEmpty()'> and kpi_code=#{kpiCode} </if>"
			+ "<if test='dateType!=null'> and date_type=#{dateType} </if>"
			+ "<if test='dateValue!=null and !deptCode.isEmpty()'> and date_value=#{dateValue} </if>"
			+ "<if test='statisticalType!=null'> and statistical_type=#{statisticalType} </if>"
			+ "<if test='objectId!=null and !objectId.isEmpty()'> and object_id=#{objectId} </if>"
			+ "<if test='objectName!=null'> and object_name like CONCAT(CONCAT('%',#{objectId}),'%') </if>"
			+ "order by date_value desc"
			+ "<if test='start!=null and end!=null'> limit #{start},#{end} </if>"
			+ "</script>")
	List<KpiStatistics> query(KpiStatisticsBean bean);
	
	@Select("<script>"
			+ "select count(*) from kpi_statistical where 1=1"
			+ "<if test='kpiId!=null and !kpiId.isEmpty()'> and kpi_id=#{kpiId} </if>"
			+ "<if test='kpiName!=null'> and kpi_name like CONCAT(CONCAT('%',#{kpiName}),'%') </if>"
			+ "<if test='kpiCode!=null and !kpiCode.isEmpty()'> and kpi_code=#{kpiCode} </if>"
			+ "<if test='dateType!=null'> and date_type=#{dateType} </if>"
			+ "<if test='dateValue!=null and !deptCode.isEmpty()'> and date_value=#{dateValue} </if>"
			+ "<if test='statisticalType!=null'> and statistical_type=#{statisticalType} </if>"
			+ "<if test='objectId!=null and !objectId.isEmpty()'> and object_id=#{objectId} </if>"
			+ "<if test='objectName!=null'> and object_name like CONCAT(CONCAT('%',#{objectId}),'%') </if>"
			+ "</script>")
	int count(KpiStatisticsBean bean);
}
